package com.qing.service.impl;

import com.qing.dao.*;
import com.qing.domain.*;
import com.qing.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class PostServiceImpl implements PostService {
    private final PostDao postDao;
    private final BoardDao boardDao;
    @Autowired
    public PostServiceImpl(PostDao postDao,BoardDao boardDao){this.boardDao=boardDao;this.postDao=postDao;}

    @Override
    public void addPostByPost(Post post){ postDao.addPost(post);}/*** 添加文章* @param post 新增的文章 */
    public Post getPost(int postId){return postDao.findPostByPostId(postId);}/*** 获取文章内容* @param postId 文章 id* @return 文章内容     */
    public List<Post> listAllPost(){return postDao.listAllPostInfo();}/*** 获取所有文章* @return 文章列表   */
    public void deletePost(int postId){
        int boardId=postDao.findPostByPostId(postId).getPostBoardId();
        Board board=boardDao.findBoardByBoardId(boardId);
        board.setBoardPostNum(board.getBoardPostNum()-1);
        boardDao.updateBoardByBoard(board);//更新Board数据（帖子数）
        //删除帖子数据库数据
        postDao.deletePostById(postId);
        //那个附件怎么办，path没了
    }
}
